package com.rc.common.config;

import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {

//    @Bean
//    public CustomExchange delayedExchange(){
//        Map<String, Object> args = new HashMap<>();
//        //自定义交换机的类型
//        args.put("x-delayed-type", "topic");
//        return new CustomExchange("order.exchange", "x-delayed-message", true, false, args);
//    }
//
//    /**
//     * 订单超时队列
//     * @return
//     */
//    @Bean
//    public Queue queue() {
//        return new Queue("order.expiration.queue",true);
//    }
//
//    @Bean
//    public Binding bindingQueue1(){
//        return BindingBuilder.bind(queue()).to(delayedExchange()).with("order.expiration").noargs();
//    }


    @Bean
    public MessageConverter messageConverter(){
        // 1.定义消息转换器
        Jackson2JsonMessageConverter jackson2JsonMessageConverter = new Jackson2JsonMessageConverter();

        // 2.配置自动创建消息id，用于识别不同消息，也可以在业务中基于ID判断是否是重复消息
        jackson2JsonMessageConverter.setCreateMessageIds(true);
        return jackson2JsonMessageConverter;
    }
}
